<template>
  <div class="recommon">
    <div class="item" v-for="item in list" :key="item.id">
      <div class="top">
        <img :src="item.avatar" alt="" />
        <div class="head">
          <div class="title">{{ item.stem }}</div>
          <div class="info">
            <div class="name">{{ item.creator }}</div>
            <div>|</div>
            <div class="date">{{ item.createdAt }}</div>
          </div>
        </div>
      </div>
      <div class="content">{{ item.content }}</div>
      <div class="bottom">
        <div class="like">点赞 {{ item.likeCount }}</div>
        |
        <div class="look">浏览 {{ item.views }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      list: [],
    };
  },
  methods: {
    async getData() {
      const res = await axios({
        url: "http://interview-api-t.itheima.net/h5/interview/query",
        headers: {
          "Content-Type": "application/json",
          Authorization: `Bearer ${localStorage.getItem("token")}`,
        },
        params: {
          current: 1,
          pageSize: 10,
        },
      });
      this.list = res.data.data.rows;
    },
  },
  created() {
    this.getData();
  },
};
</script>

<style lang="less" scoped>
.recommon {
  .item {
    margin-bottom: 10px;
    border-top: 1px #ccc solid;
    .top {
      display: flex;
      margin-bottom: 5px;
      img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        margin-right: 10px;
      }
      .head {
        height: 50px;
        flex: 1;
        text-align: left;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 8px 0;
        .title {
          font-size: 14px;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 1; /* 设置行数 */
          overflow: hidden;
        }
        .info {
          display: flex;
          color: #ccc;
          font-size: 12px;
        }
      }
    }
    .content {
      font-size: 14px;
      line-height: 16px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 3; /* 设置行数 */
      overflow: hidden;
      margin-bottom: 5px;
    }
    .bottom {
      display: flex;
      color: #ccc;
      font-size: 12px;
    }
  }
}
</style>
